# $Id$
# Maintainer: Eric Bélanger <eric@archlinux.org>

pkgname=libtiff
pkgver=4.0.9
pkgrel=2
pkgdesc="Library for manipulation of TIFF images"
arch=('x86_64')
url="http://www.simplesystems.org/libtiff/"
license=('custom')
depends=('libjpeg' 'zlib' 'xz')
makedepends=('freeglut' 'glu' 'mesa' 'jbigkit')
optdepends=('freeglut: for using tiffgt')
source=(http://download.osgeo.org/libtiff/tiff-${pkgver}.tar.gz
        CVE-2017-18013.patch::"https://gitlab.com/libtiff/libtiff/commit/c6f41df7.diff"
        CVE-2018-5784.patch::"https://gitlab.com/libtiff/libtiff/commit/473851d2.diff"
        CVE-2018-7456.patch::"https://gitlab.com/libtiff/libtiff/commit/be4c85b1.diff"
        CVE-2018-8905.patch::"https://gitlab.com/libtiff/libtiff/commit/58a898cb.diff"
        CVE-2018-10963.patch::"https://gitlab.com/libtiff/libtiff/commit/de144fd2.diff")
sha256sums=('6e7bdeec2c310734e734d19aae3a71ebe37a4d842e0e23dbb1b8921c0026cfcd'
            'ea49366f085d324073bdbcc183db9b190e7ff4178649daf158e91ea1cfb12fef'
            'b93ff957acc1236481e9c5f33844334c62f3636d575f5f2cc418491349ebe7a5'
            '2e00f46633e205fb6ed04957f07c5b13e3cc527876076c3cbda80f3894220909'
            '8aed7c35dd2fb79af16a704a95cddff2852f85dbb019e9e9cdb54638b529935b'
            'f3c46de22050adad6da91498c549562af833d48e84028f36da5ec0387534e8af')

prepare() {
  cd tiff-$pkgver
# Security fixes
  patch -p1 -i ../CVE-2017-18013.patch
  patch -p1 -i ../CVE-2018-5784.patch
  patch -p1 -i ../CVE-2018-7456.patch
  patch -p1 -i ../CVE-2018-8905.patch
  patch -p1 -i ../CVE-2018-10963.patch
}

build() {
  cd tiff-${pkgver}
  ./configure --prefix=/usr
  sed -i -e 's/ -shared / -Wl,-O1,--as-needed\0/g' libtool
  make
}

check() {
  cd tiff-${pkgver}
  make check
}

package() {
  cd tiff-${pkgver}
  make DESTDIR="${pkgdir}" install
  install -D -m644 COPYRIGHT "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"
}
